<?php

class Sherpa_Model_BaseGateway extends WSB_Model_Gateway
{

	/**
	 * @var boolean
	 */
	protected $_useCache = false;

    /**
     * @param  boolean $flag
     */
	public function setUseCache($flag)
	{
		$this->_useCache = (bool)$flag;
	}

	/**
	 * @return boolean
	 */
	public function useCache()
	{
		return $this->_useCache;
	}

	/**
	 * @param Sherpa_Model_BaseGateway $cachedEntity
	 * @return Zend_Cache_Frontend_Class
	 */
	public function getCacheInstance(Sherpa_Model_BaseGateway $cachedEntity)
	{
		$frontendOptions = array(
		   'cached_entity' => $this
		);
		$backendOptions = array('cache_dir' => WSB_CACHE_DIR . 'sherpa');
		$cache = Zend_Cache::factory('Class', 'File', $frontendOptions, $backendOptions);
		return $cache;
	}

	/**
	 * @param Zend_Db_Select $select (Call by reference)
	 * @param $fromField string
	 * @param $toField stromg
	 * @return void
	 */
	protected function _setActiveWhereClause(Zend_Db_Select $select, $fromField, $toField)
	{
		$where = sprintf(
			'(%1$s IS NULL OR %1$s < NOW()) AND (%2$s IS NULL OR %2$s > NOW())',
			$fromField,
			$toField
		);
		$select->where($where);
	}

	/**
	 * @param Zend_Db_Select $select (Call by reference)
	 * @param $fromField string
	 * @param $toField stromg
	 * @return void
	 */
	protected function _setAvailableWhereClause(Zend_Db_Select $select, $fromField, $toField)
	{
		$where = sprintf('(%1$s IS NULL OR %1$s < NOW()) AND (%2$s IS NULL OR %2$s > NOW())',
			$fromField,
			$toField
		);
		$select->where($where);
	}

}
